-
Notifications
You must be signed in to change notification settings - Fork 7.9k
uri: Improve safety of URI object initialization #19648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…lers()` There is no one time fits all solution to initialization of the object handlers. A follow-up commit will use distinct `create_object` handlers for each parser class. Explicitly spelling out the handlers is a well-established pattern in php-src and I don't see a reason to diverge from that with an intransparent helper method.
239b203
to
47b8e57
Compare
For the RMs: This is halfway between feature and bugfix. It doesn't fix an actual bug, but will make the URI objects much more robust internally, since they are created in a “safe state”. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RM approval, minimal technical review performed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly fine, one nit where I think at least the commit message should be updated to not be misleading
…pon creation This makes the objects much safer to use, since the `.parser` will always be available and matching the object.
The parser for a given object is already known from the object itself and particularly must never change. Reassigning the value in `uri_unserialize()` is just unsafe, especially since the existing `->uri` is freed with the destructor of the reassigned parser. Just rely on the `->parser` field being set to the correct value.
Similarly to the previous change to `uri_unserialize()`, the `->parser` must always match the object for the freeing to be safe. Given that we expect to successfully parse URIs, we can eagerly initialize the resulting URI object when using the `::parse()` methods and destruct it again when parsing fails and `null` is returned instead. Calling the destructor is safe, since `uri` will be `NULL`, which will result in a noop. The `base_url_object` must also match the object that is currently being constructed. Verify this using assertions matching the `->ce` and the `->parser`.
47b8e57
to
89c1327
Compare
See individual commits.